﻿using Microsoft.Xna.Framework.Graphics;

namespace Deferred.Library.Scene.Graphics
{
    class DeferredModelMeshPart
    {
        public int TriangleCount = 0;
        public int VertexCount = 0;
        public int VertexStride = 0;

        public string TextureName;
        public Texture2D Texture;
        public string NormalMapName;
        public Texture2D NormalMap;
        public string SpecularMapName;
        public Texture2D SpecularMap;

        public VertexDeclaration VertexDeclaration = null;
        public VertexBuffer VertexBuffer = null;
        public IndexBuffer IndexBuffer = null;

        public void LoadContent(DualContentManager content)
        {
            Texture = getTexture(content, TextureName, "_default");
            SpecularMap = getTexture(content, SpecularMapName, "null_specular");
            NormalMap = getTexture(content, NormalMapName, "null_normal");
        }

        private Texture2D getTexture(DualContentManager content, string name, string defaultName)
        {
            if (string.IsNullOrEmpty(name))
            {
                return content.InternalContent.Load<Texture2D>(defaultName);
            }
            else
            {
                return content.ExternalContent.Load<Texture2D>("Textures\\" + name);
            }
        }
    }
}
